package com.fivefu.core.hik.services.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fivefu.base.common.utils.date.DateUtils;
import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.core.hik.constant.HikRequestTypeEnum;
import com.fivefu.core.hik.dto.request.VideoShowStringReq;
import com.fivefu.core.hik.dto.response.*;
import com.fivefu.core.hik.properties.HikProperties;
import com.fivefu.core.hik.services.HikvisionService;
import com.fivefu.core.hik.services.VideoService;
import com.fivefu.core.hik.utils.ISODateUtils;
import com.fivefu.core.hik.vo.VideoOSDVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class VideoServiceImpl implements VideoService {

    @Autowired
    private HikvisionService hikvisionService;
    @Autowired
    private HikProperties hikProperties;

    /**
     * 查询视频播放地址
     * @param cameraIndexCode 监控点编号
     * @param protocol 取流协议(hik,rtsp,rtmp,hls,ws,默认hik)
     * @return
     */
    @Override
    public String getCameraPreviewURLs(String cameraIndexCode, String protocol){
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        if (StrUtils.isNotNull(protocol)) {
            obj.put("protocol", protocol);
        }
        //查询参数
        String body = JSON.toJSONString(obj);

        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.PREVIEWURLSV2;
        if (hikProperties.getPreviewURLVersion() != null && hikProperties.getPreviewURLVersion().equals(1)){
            typeEnum = HikRequestTypeEnum.PREVIEWURLSV1;
        }

        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            //获取到取流URL(例："url":"rtsp://172.16.248.20:554/openUrl/LsgZ5Yc")
            if (StrUtils.isNotNull(resultData)) {
                return resultData;
            }
        }
        return null;
    }

    /**
     * 查询视频历史流播放地址
     * @param cameraIndexCode 监控点编号
     * @param protocol 取流协议(hik,rtsp,rtmp,hls,ws,默认hik)
     * @return
     */
    @Override
    public String getCameraBackURL(String cameraIndexCode,Integer recordLocation, String protocol,String sTime,String eTime){
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        if (StrUtils.isNotNull(protocol)) {
            obj.put("protocol", protocol);
        }
        obj.put("beginTime", ISODateUtils.formatLocalDateTimeToISODate(DateUtils.parse(sTime)));
        obj.put("endTime",ISODateUtils.formatLocalDateTimeToISODate(DateUtils.parse(eTime)));
        if (recordLocation != null){
            obj.put("recordLocation",recordLocation);
        }
        //查询参数
        String body = JSON.toJSONString(obj);

        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.PLAYBACKURLSV2;
        if (hikProperties.getPlayBackURLVersion() != null && hikProperties.getPlayBackURLVersion().equals(1)){
            typeEnum = HikRequestTypeEnum.PLAYBACKURLSV1;
        }

        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            //获取到取流URL(例："url":"rtsp://172.16.248.20:554/openUrl/LsgZ5Yc")
            //"data":{"uuid":"","url":null,"list":null}返回格式
            if (StrUtils.isNotNull(resultData)) {
                return resultData;
            }
        }
        return null;
    }

    /**
     * 云台控制   根据监控点编号进行云台操作
     * @param cameraIndexCode  监控点编号
     * @param action    开始/停止转到预置点
     * @param operation   操作类型
     */
    @Override
    public void operationHolder(String cameraIndexCode, Integer action, String operation,Integer speed, Integer presetIndex) {
        //根据操作类型去db_sys_dict表中查询相对应的海康请求值
//        String command = dbSysDictService.queryDictValueByOperation(operation);
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("action",action);
        obj.put("command",operation);
        if (speed != null){
            obj.put("speed",speed);
        }
        if (presetIndex != null){
            obj.put("presetIndex",presetIndex);
        }
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.HOLDER;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //云台操作无返回值，看msg信息
            //"code":"0","msg":"success","data":""
            //System.out.println(msg);
        }
    }

    /**
     * 3D放大   监控点3D放大
     * @param cameraIndexCode  监控点唯一标识
     * @param startX   开始放大的X坐标
     * @param startY   开始放大的Y坐标
     * @param endX     结束放大的X坐标
     * @param endY     结束放大的Y坐标
     */
    @Override
    public void threeDAmplification(String cameraIndexCode, Integer startX, Integer startY, Integer endX, Integer endY) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("startX",startX);
        obj.put("startY",startY);
        obj.put("endX",endX);
        obj.put("endY",endY);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.THREEDAMPLIFICATION;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        ThreeDAmplificationResp threeD = new ThreeDAmplificationResp();
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                threeD = JSON.parseObject(resultData, ThreeDAmplificationResp.class);
                //返回结果：用户等级和用户编号
                //"code":"0","msg":"success","data":{"userId":"sjdj","priority":2}
                //System.out.println(threeD);
            }
        }
    }

    /**
     * 手动录像-录像锁定与解锁
     * @param cameraIndexCode  监控点唯一标识
     * @param startTime  开始时间
     * @param endTime    结束时间
     * @param lockTime   锁定时长
     */
    @Override
    public void lockVideo(String cameraIndexCode, String startTime, String endTime, Integer lockTime) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("startTime",startTime);
        obj.put("endTime",endTime);
        obj.put("lockTime",lockTime);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.LOCKRECORD;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            //测试数据：a5e199d850624e14850e2700480d3931
            //"code":"0","msg":"success","data":null
            //String msg = result.getMsg();
            //System.out.println(msg);
        }
    }

    /**
     * 手动录像-开关手动录像
     * @param cameraIndexCode  监控点唯一标识
     * @param operation        操作类型（1：开始，2：关闭）
     * @param recordType       录像类型
     */
    @Override
    public void switchVideo(String cameraIndexCode, Integer operation,Integer recordType) {
        if (1 == operation) {
            openVideo(cameraIndexCode,recordType);
        } else {
            closeVideo(cameraIndexCode);
        }
    }

    /**
     * 手动录像-获取手动录像状态
     * @param cameraIndexCode  监控点唯一标识
     */
    @Override
    public void getVideoStatus(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("taskID",1);//手动录像编号也需要
        //存储类型默认为中心存储0
        obj.put("type",0);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.VIDEOSTATUS;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            //返回手动录像状态:  0-未接入   1-正常执行  2-异常
            String taskStatus = result.getData().toString();
            //System.out.println(taskStatus);
        }
    }

    /**
     * 手动录像-查询手动录像编号
     * @param cameraIndexCodes  监控点编号集合
     */
    @Override
    public void getVideoNumber(String[] cameraIndexCodes) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCodes",cameraIndexCodes);
        //封装为json字符串
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.VIDEONUMBER;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {//调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //将json字符串转换为json对象
                JSONObject jsonObj = JSON.parseObject(resultData);
                Map<String,Object> videoMap = new HashMap<>();
                //循环转换
                Set<Map.Entry<String, Object>> entrySet = jsonObj.entrySet();
                for (Map.Entry<String, Object> stringObjectEntry : entrySet) {
                    videoMap.put(stringObjectEntry.getKey(),stringObjectEntry.getValue());
                }
                HikVideoNumberResp videoNumberResp = new HikVideoNumberResp();
                videoNumberResp.setUserId(videoMap.get("userId").toString());
                videoNumberResp.setManualRecordTask((List<VideoIndex>) videoMap.get("manualRecordTask"));
                //System.out.println(videoNumberResp);"code":"0","msg":"success","data":{"userId":"sjdj","manualRecordTask":[]}
            }
        }
    }

    /**
     *  预置点管理-设置预置点信息
     * @param cameraIndexCode  监控点唯一标识
     * @param presetName       预置点名称
     * @param presetIndex      预置点编号
     */
    @Override
    public void setPresetPoint(String cameraIndexCode, String presetName, Integer presetIndex) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("presetName",presetName);
        obj.put("presetIndex",presetIndex);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.PRESETPOINT;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);"code":"0","msg":"success","data":null
        }
    }

    /**
     * 预置点管理-查询预置点信息
     * @param cameraIndexCode  监控点唯一标识
     */
    @Override
    public ResponsePage getPresetPoint(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode", cameraIndexCode);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.QUERTPRESETPOINT;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        ResponsePage resultPage = new ResponsePage();
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                resultPage = JSON.parseObject(resultData, ResponsePage.class);
                //没数据库，暂时打印输出
                //"code":"0","msg":"success","data":{"total":1,
                // "list":[{"presetPointName":"预置点1","presetPointIndex":1,"cameraIndexCode":"a5e199d850624e14850e2700480d3931"}]}
                //System.out.println(resultPage);
            }
        }
        return resultPage;
    }

    /**
     * 预置点管理-删除预置点信息
     * @param cameraIndexCode  监控点唯一编号
     * @param presetIndex      预置点编号
     */
    @Override
    public void deletePresetPoint(String cameraIndexCode, String presetIndex) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode", cameraIndexCode);
        obj.put("presetIndex", presetIndex);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.DELETEPRESETPOINT;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);"code":"0","msg":"success","data":null
        }
    }

    /**
     * 预置点管理-批量获取监控点的预置点信息
     * @param cameraIndexCodes  监控点唯一标识集和
     */
    @Override
    public void batchQueryCameraIndexCodeInfo(String[] cameraIndexCodes) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCodes",cameraIndexCodes);
        //封装为json字符串
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.BATCHPRESETPOINT;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        ResponsePage resultPage = new ResponsePage();
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                resultPage = JSON.parseObject(resultData, ResponsePage.class);
                //没数据库，暂时打印输出
                //"code":"0","msg":"success","data":{"total":1,
                // "list":[{"cameraIndexCode":"a5e199d850624e14850e2700480d3931","presetPoints":[{"presetPointName":"预置点1","presetPointIndex":1}]}]}
                //System.out.println(resultPage);
            }
        }
    }

    /**
     * 图片获取-平台抓拍计划图片获取
     * @param sTime  开始时间
     * @param eTime  结束时间
     */
    @Override
    public void getPlatformSnapped(String sTime, String eTime) {
        Integer pageNo = 3;
        Integer pageSize = 100;
        platformSnapped(pageNo,pageSize,sTime,eTime);
    }

    /**
     * 图片获取-视频图片查询
     * @param svrIndexCode  图片存储服务器唯一标识
     * @param picUri        图片的相对地址
     */
    @Override
    public void getVideoImages(String svrIndexCode, String picUri) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("svrIndexCode",svrIndexCode);
        obj.put("picUri",picUri);
        obj.put("netProtocol","http");
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.VIDEOIMAGES;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //返回图片url，有效期24小时
                //System.out.println(resultData);
            }
        }
    }

    /**
     * 巡航路径-查询巡航路径
     * @param cameraIndexCode    监控点唯一编号
     */
    @Override
    public void getCruisePath(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.QUERYCRUISEPATH;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        ResponsePage resultPage = new ResponsePage();
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                resultPage = JSON.parseObject(resultData, ResponsePage.class);
                //没数据库，暂时打印输出   接口调用无问题，但返回信息中total:0  list []
                //System.out.println(resultPage);
            }
        }
    }

    /**
     * 巡航路径-编辑巡航路径
     * @param cameraIndexCode   监控点唯一标识
     * @param cruiseIndex       巡航路径序号
     * @param presetPointIndex  预置点序号
     * @param speed             速度
     * @param standingTime      停留时间
     */
    @Override
    public void editorCruisePath(String cameraIndexCode, Integer cruiseIndex, Integer presetPointIndex, Integer speed, Integer standingTime) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("cruiseIndex",cruiseIndex);
        obj.put("presetPointIndex",presetPointIndex);
        obj.put("speed",speed);
        obj.put("standingTime",standingTime);
        //obj.put("cruiseName","巡航名称");//增加时必须指定
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.EDITORCRUISEPATH;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        //"code":"0x0190004e","msg":"name:hiksdk,code:11,dsc:PTZCruise failed","data":null
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);
        }
    }

    /**
     * 巡航路径-删除巡航路径
     * @param cameraIndexCode   监控点唯一编号
     * @param cruiseIndex       巡航路径序号
     */
    @Override
    public void deleteCruisePath(String cameraIndexCode, Integer cruiseIndex) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("cruiseIndex",cruiseIndex);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.DELETECRUISEPATH;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);
        }
    }

    /**
     * 巡航路径-巡航路径控制
     * @param cameraIndexCode   监控点唯一编号
     * @param command           控制命令
     * @param cruiseIndex       巡航路径序号
     */
    @Override
    public void controlCruisePath(String cameraIndexCode, String command, String cruiseIndex) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("command",command);
        obj.put("cruiseIndex",cruiseIndex);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.CONTROLCRUISEPATH;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);
        }
    }

    /**
     * 视频参数配置-获取视频OSD显示参数
     * @param cameraIndexCode   监控点唯一编号
     */
    @Override
    public void getVideoOSDDisplayParameters(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.VIDEOOSDDISPLAYPARAMETERS;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //将json字符串转换为json对象
                JSONObject jsonObj = JSON.parseObject(resultData);
                Map<String,Object> videoMap = new HashMap<>();
                //循环转换
                Set<Map.Entry<String, Object>> entrySet = jsonObj.entrySet();
                for (Map.Entry<String, Object> stringObjectEntry : entrySet) {
                    videoMap.put(stringObjectEntry.getKey(),stringObjectEntry.getValue());
                }
                VideoOSDResp videoOSDResp = new VideoOSDResp();
                videoOSDResp.setCameraIndexCode(videoMap.get("cameraIndexCode").toString());
                videoOSDResp.setChannelName(videoMap.get("channelName").toString());
                videoOSDResp.setIsShowChanName((Integer) videoMap.get("isShowChanName"));
                videoOSDResp.setChannelNameXPos((Integer) videoMap.get("channelNameXPos"));
                videoOSDResp.setChannelNameYPos((Integer) videoMap.get("channelNameYPos"));
                videoOSDResp.setHourOSDType((Integer) videoMap.get("hourOSDType"));
                videoOSDResp.setIsShowOSD((Integer) videoMap.get("isShowOSD"));
                videoOSDResp.setOsdXPos((Integer) videoMap.get("osdXPos"));
                videoOSDResp.setOsdYPos((Integer) videoMap.get("osdYPos"));
                videoOSDResp.setOsdType((Integer) videoMap.get("osdType"));
                videoOSDResp.setOsdAttrib((Integer) videoMap.get("osdAttrib"));
                videoOSDResp.setIsShowWeek((Integer) videoMap.get("isShowWeek"));
                //VideoOSDResp{cameraIndexCode='a5e199d850624e14850e2700480d3931', channelName='教堂南全景球机', isShowChanName=1,
                // channelNameXPos=464, channelNameYPos=528, hourOSDType=0, isShowOSD=1, osdXPos=0, osdYPos=0, osdType=0, osdAttrib=4, isShowWeek=0,
                // brightness=null, hue=null, contrast=null, saturation=null, showStringParams=null}
                //System.out.println(videoOSDResp);
            }
        }
    }

    /**
     * 视频参数配置-获取视频叠加字符串参数
     * @param cameraIndexCode  监控点唯一编号
     */
    @Override
    public void getVideoOverLayString(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.VIDEOOVERLAYSTRING;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {//调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //将json字符串转换为json对象
                JSONObject jsonObj = JSON.parseObject(resultData);
                Map<String,Object> videoMap = new HashMap<>();
                //循环转换
                Set<Map.Entry<String, Object>> entrySet = jsonObj.entrySet();
                for (Map.Entry<String, Object> stringObjectEntry : entrySet) {
                    videoMap.put(stringObjectEntry.getKey(),stringObjectEntry.getValue());
                }
                VideoOSDResp videoOSDResp = new VideoOSDResp();
                videoOSDResp.setCameraIndexCode(videoMap.get("cameraIndexCode").toString());
                videoOSDResp.setShowStringParams((List<VideoOSD>)videoMap.get("showStringParams"));
                //System.out.println(videoOSDResp);返回测试类参数信息
                //VideoOSDResp{cameraIndexCode='a5e199d850624e14850e2700480d3931', channelName='null', isShowChanName=null, channelNameXPos=null, channelNameYPos=null,
                // hourOSDType=null, isShowOSD=null, osdXPos=null, osdYPos=null, osdType=null, osdAttrib=null, isShowWeek=null, brightness=null, hue=null, contrast=null,
                // saturation=null, showStringParams=[{"showString":"","yPos":0,"xPos":0,"isShow":0},{"showString":"","yPos":0,"xPos":0,"isShow":0},
                // {"showString":"","yPos":0,"xPos":0,"isShow":0},{"showString":"","yPos":0,"xPos":0,"isShow":0}]}
            }
        }
    }

    /**
     * 视频参数配置-获取预览画面参数配置
     * @param cameraIndexCode  监控点唯一编号
     */
    @Override
    public void getVideoParams(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.VIDEOPARAMA;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {//调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //将json字符串转换为json对象
                JSONObject jsonObj = JSON.parseObject(resultData);
                Map<String,Object> videoMap = new HashMap<>();
                //循环转换
                Set<Map.Entry<String, Object>> entrySet = jsonObj.entrySet();
                for (Map.Entry<String, Object> stringObjectEntry : entrySet) {
                    videoMap.put(stringObjectEntry.getKey(),stringObjectEntry.getValue());
                }
                VideoOSDResp videoOSDResp = new VideoOSDResp();
                videoOSDResp.setCameraIndexCode(videoMap.get("cameraIndexCode").toString());
                videoOSDResp.setBrightness((Integer) videoMap.get("brightness"));
                videoOSDResp.setHue((Integer) videoMap.get("hue"));
                videoOSDResp.setContrast((Integer) videoMap.get("contrast"));
                videoOSDResp.setSaturation((Integer) videoMap.get("saturation"));
                //System.out.println(videoOSDResp);返回测试参数信息
                //VideoOSDResp{cameraIndexCode='a5e199d850624e14850e2700480d3931', channelName='null', isShowChanName=null, channelNameXPos=null,
                // channelNameYPos=null, hourOSDType=null, isShowOSD=null, osdXPos=null, osdYPos=null, osdType=null, osdAttrib=null, isShowWeek=null,
                // brightness=5, hue=5, contrast=5, saturation=5, showStringParams=null}
            }
        }
    }

    /**
     * 视频参数配置-设置视频OSD显示参数
     * @param videoOSDVo
     */
    @Override
    public void setOSDParams(VideoOSDVo videoOSDVo) {
        //将请求参数转为json字符串
        String body = JSON.toJSONString(videoOSDVo);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.OSDPARAMS;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);"code":"0","msg":"success","data":null
        }
    }

    /**
     * 视频参数配置-设置预览画面参数配置
     * @param cameraIndexCode  监控点唯一编号
     * @param brightness       亮度
     * @param hue              灰度
     * @param contrast         对比度
     * @param saturation       饱和度
     */
    @Override
    public void setPreViewPictureParams(String cameraIndexCode,Integer brightness,Integer hue,Integer contrast,Integer saturation) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("brightness",brightness);
        obj.put("hue",hue);
        obj.put("contrast",contrast);
        obj.put("saturation",saturation);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.PREVIEWPICTUREPARAMS;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);
            // "code":"0","msg":"success","data":null
        }
    }

    /**
     * 视频参数配置-设置视频叠加字符串参数
     * @param cameraIndexCode    监控点唯一编号
     * @param showString         叠加字符串文本内容
     * @param isShow            是否显示叠加内容
     * @param xPos           显示X坐标
     * @param yPos           显示Y坐标
     */
    @Override
    public void setVideoOverLayString(String cameraIndexCode, String showString, Integer isShow, Integer xPos, Integer yPos) {
        VideoShowStringReq videoShowStringReq = new VideoShowStringReq();
        videoShowStringReq.setCameraIndexCode(cameraIndexCode);
        Object[] obj = {"showString:"+showString,"isShow:"+isShow,"xPos:"+xPos,"yPos:"+yPos};
        videoShowStringReq.setShowStringParams(obj);
        //将请求参数转为json字符串
        String body = JSON.toJSONString(videoShowStringReq);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.OSDDISPLAYPARAMETERS;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);
            // "code":"0","msg":"success","data":null
        }
    }

    /**
     * 图片获取-平台抓拍计划图片获取
     * @param pageNo     当前页
     * @param pageSize   每页显示条数
     * @param sTime
     * @param eTime
     */
    private void platformSnapped(Integer pageNo, Integer pageSize, String sTime, String eTime) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("pageNo",pageNo);
        obj.put("pageSize",pageSize);
        obj.put("startTime",sTime);
        obj.put("endTime",eTime);
        String[] cameraIndexCodes ={"a5e199d850624e14850e2700480d3931"};
        obj.put("cameraIndexCodes",cameraIndexCodes);
        obj.put("captureId","8a4cef50-3679-424f-8e23-6e2895ed0415");
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.PLATFORMSNAPPED;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        ResponsePage resultPage = new ResponsePage();
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                resultPage = JSON.parseObject(resultData, ResponsePage.class);
                //没数据库，暂时打印输出
                //System.out.println(resultPage);"code":"0","msg":"success","data":{"total":0,"pageNo":0,"pageSize":400,"list":[]}
            }
        }
    }

    /**
     * 停止手动录像
     * @param cameraIndexCode  监控点唯一标识
     */
    private void closeVideo(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //手动录像编号
        obj.put("taskID","1");
        //默认存储类型为中心存储0
        obj.put("type",0);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.CLOSERECORD;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String msg = result.getMsg();
            //System.out.println(msg);
        }
    }

    /**
     * 开始手动录像
     * @param cameraIndexCode  监控点唯一标识
     * @param recordType       录像类型
     */
    private void openVideo(String cameraIndexCode,Integer recordType) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //recordType 也是必传参数和官网给的有出入
        obj.put("recordType",recordType);
        //存储类型，默认为中心存储0，因此recordType为必填
        obj.put("type",0);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.OPENRECORD;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //返回任务编号taskID
                //System.out.println(resultData);
            }
        }
    }

    /**
     * 抓图
     * @param cameraIndexCode  监控点唯一标识
     */
    @Override
    public String getManualCapture(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.MANUALCAPTURE;
        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //返回一个图片URL信息
                //"code":"0","msg":"success",
                // "data":{"picUrl":"http://172.16.254.199:6120/pic?did=1&bid=7872742&pid=1073741824&size=179362&ptime=1658281392&AccessKeyId=ernyltjntgbidwhdqbovkxsulwkvqmexftvrmeegnhoqfxvvzjsjilftjprb&Expires=1658367792&Signature=dXMYxoYl7QGB+RWZFIT0rLMaWlk="}
                //System.out.println(resultData);
                return resultData;
            }
        }
        return null;
    }

    /**
     * 语音对讲
     * @param cameraIndexCode  监控点唯一标识
     */
    @Override
    public void getCamerasTalkURLs(String cameraIndexCode) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        //查询参数
        String body = JSON.toJSONString(obj);
        //查询类型枚举
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.TALKURLSV1;
        if (hikProperties.getTalkURLVersion() != null && hikProperties.getTalkURLVersion().equals(3)){
            typeEnum = HikRequestTypeEnum.TALKURLSV3;
        }

        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            if (StrUtils.isNotNull(resultData)) {
                //返回一个rtsp地址信息
                //the Artemis Request is Success,statusCode:200
                // SuccessMsg:{"code":"0","msg":"success","data":{"url":"rtsp://172.16.248.20:554/openUrl/TmWyzwA"}}
                //System.out.println(resultData);
            }
        }
    }

    /**
     *  获取监控点回放取流URLv2  录像回放
     * @param cameraIndexCode   监控点唯一标识
     * @param beginTime  开始查询时间
     * @param endTime    结束查询时间
     */
    private void getCameraPlaybackURLs(String cameraIndexCode, String beginTime, String endTime) {
        //将请求参数转为json字符串
        JSONObject obj = new JSONObject();
        obj.put("cameraIndexCode",cameraIndexCode);
        obj.put("beginTime",beginTime);
        obj.put("endTime",endTime);
        //查询参数
        String body = JSON.toJSONString(obj);

        //查询枚举类型
        HikRequestTypeEnum typeEnum = HikRequestTypeEnum.PLAYBACKURLSV2;
        if (hikProperties.getPlayBackURLVersion() != null && hikProperties.getPlayBackURLVersion().equals(1)){
            typeEnum = HikRequestTypeEnum.PLAYBACKURLSV1;
        }

        //调用封装好的海康接口
        ResponseResult result = hikvisionService.doPostString(typeEnum.getUrl(), body, null, null, typeEnum.getType());
        if (null != result && "0".equals(result.getCode())) {
            //调用成功
            String resultData = result.getData().toString();
            //resultData结构：一个list数组，uuid:分页标记，url：取短流url
            //"code":"0","msg":"success","data":{"uuid":"","url":null,"list":null}
            if (StrUtils.isNotNull(resultData)) {
                //System.out.println(resultData);
            }
        }
    }
}
